<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="java.util.Set"%>
<%@page import="com.sks.bean.pojo.Config"%>
<%@page import="java.util.List"%>
<%@ include file="../share/taglib.jsp" %>
<html>
<head>
<title><bean:message key="display.${houseForm.method eq 'edit' ? 'edit' : 'add' }"/><bean:message key="info.house.name"/></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/css/vip.css" type="text/css">
<%@ include file="/sks/cms/page/share/validate.inc" %>
<%@ include file="/sks/js/datePicker.inc" %>
<%
boolean canEdit = !StringUtil.toBoolean(request.getAttribute("sks.isReadOnly"), false);
%>
<% if (canEdit) { %>
<script type="text/javascript" src="/js/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="/js/jscripts/tiny_mce/button_style/default.js"></script>
<script type="text/javascript" src="/js/jscripts/tiny_mce/button_style/simple.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init(getDefaultButtonStyle("intro,mapInfo"));
tinyMCE.init(getSimpleButtonStyle("remark"));

function getAreas() {
   var select = document.getElementById('topAreaId');
   var index = select.options[select.selectedIndex].value;
   $.post("/cms/house/area.do", {method:"getAreasByTopId", areaId:index},
      function (data, textStatus){
         var areaSelect = document.getElementById('areaId');
         while(areaSelect.options.length>0) {
            areaSelect.removeChild(areaSelect.options[0]);
         }
         for (var i=0; i<data.length; i++) {
            var option = document.createElement('option');
            option.innerHTML = data[i].name;
            option.value = data[i].areaId;
            areaSelect.appendChild(option);
         }
         
      }, "json");
}
function getStations() {
   var select = document.getElementById('metroId');
   var index = select.options[select.selectedIndex].value;
   $.post("/cms/house/metro.do", {method:"getStations", metroId:index},
      function (data, textStatus){
         var stationSelect = document.getElementById('metroStationId');
         while(stationSelect.options.length>0) {
        	 stationSelect.removeChild(stationSelect.options[0]);
         }
         for (var i=0; i<data.length; i++) {
            var option = document.createElement('option');
            option.innerHTML = data[i].name;
            option.value = data[i].stationId;
            stationSelect.appendChild(option);
         }
         
      }, "json");
}
function openSelectWindow() {
	 var result = window.showModalDialog("/cms/house/building.do?method=selectBuildingUI&ts=" + new Date().getTime(), window, "center=yes");
	 if (null == result) {
		 return;
	 }
	 var bId = result[0];
	 var bName = result[1];
	 document.getElementById('buildingNameLabel').innerHTML = bName;
	 document.getElementById('buildingId').value = bId;
}
function deleteBuilding() {
	document.getElementById('buildingNameLabel').innerHTML = '-';
	document.getElementById('buildingId').value = '';
}

function openSelectUsers() {
	var result = window.showModalDialog("/cms/privilege/users/list.do?query=true&isSelect=true&ts=" + new Date().getTime(), window, "center=yes");
	 if (null == result) {
		 return;
	 }
	 var uId = result[0];
	 var uName = result[1];
	 document.getElementById('userNameLabel').innerHTML = uName;
	 document.getElementById('userId').value = uId;
}
function deleteUser() {
	document.getElementById('userNameLabel').innerHTML = '-';
	document.getElementById('userId').value = '';
}

function selectAll(ids, keyCheck) {
	var checks = document.getElementsByName(ids);
	for (var i = 0; i < checks.length; i++) {
		var c = checks[i];
		if (c.type == 'checkbox') {
			c.checked = keyCheck.checked;
		}
	}
}

</script>
<% } %>
<script type="text/javascript">
$(function() {
	$( "#beginDate" ).datepicker({
		changeMonth: true,
		changeYear: true
	});
});
var compareValidator = new tt.CV();
function bodyOnLoad() {
	tt.vf.req.add('title', 'address', 'space');
	tt.vf.int.add("floorAll", "floorAt");
	new tt.LV().set(0, 100).add("title", "community");
	new tt.LV().set(0, 200).add("address", "managePrice");
	new tt.NRV().set(0, '++').add("space", "floorAll", "floorAt");//'++'表示无穷大
	new tt.DV().set("yyyy-mm-dd").add("beginDate");
	compareValidator.add(new tt.Field("总楼层", "floorAll")).set('n', ">=", new tt.Field("所在楼层", "floorAt"));
	${houseForm.method eq 'edit' ? 'tt.validate();' : ''}
}
function changeStatus(status) {
	if (!status) {
		return;
	}
	if(!confirm('你确定要执行该操作吗？')) {
		return;
	}
	window.location.href = "<%=basePath%>cms/house.do?method=changeStatus&houseId=${houseForm.houseId}&houseStatus=" + status;
}

function openSelectEmployee() {
	 var result = window.showModalDialog("/cms/privilege/employee/list.do?isSelect=true&ts=" + new Date().getTime(), window);
	 if (null == result) {
		 return;
	 }
	 document.getElementById('employeeNameLabel').innerHTML = result;
	 document.getElementById('employeeName').value = result;

	 <c:if test="${houseForm.method eq 'edit'}">
	 /*$.post("/cms/house.do", {method:"saveEmployee", houseId:${houseForm.houseId}, employeeName:result},
      function (data, textStatus){
         if (null != data.success && data.success) {
             alert("保存负责人成功");
         } else {
        	 alert("保存负责人失败");
         }
      }, "json");*/
	 </c:if>
}
function deleteEmployee() {
	document.getElementById('employeeNameLabel').innerHTML = '-';
	document.getElementById('employeeName').value = '';
}
</script>
</head>
<body onload="bodyOnLoad();" bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<html:form styleId="houseForm" action="/cms/house.do" method="post" onsubmit="return tt.validate();">
<html:hidden property="houseId"/>
<html:hidden property="type"/>
<html:hidden property="isHot"/>
<html:hidden property="houseStatus"/>
<input type="hidden" name="method" value="${houseForm.method}">
  <table width="90%" border="0" cellspacing="2" cellpadding="3" align="center">
    <tr bgcolor="#ffbe26">
    	<td colspan="2">
    		<%@ include file="houseMenu.inc"%>
    	</td>
    </tr>
    <c:if test="${canAudit}">
    <tr bgcolor="f5f5f5"> 
      <td colspan="2">
      <c:if test="${houseForm.houseStatus eq 'noneAudit'}">
      	<button type="button" onclick="changeStatus('audited');">审核通过</button>
      </c:if>
      <c:if test="${houseForm.houseStatus eq 'audited'}">
      	<button type="button" onclick="changeStatus('noneAudit');">撤销审核</button>
      	<button type="button" onclick="changeStatus('published');">发布</button>
      </c:if>
      <c:if test="${houseForm.houseStatus eq 'published'}">
      	<button type="button" onclick="changeStatus('audited');">撤销发布</button>
      	<button type="button" onclick="changeStatus('finished');">完成交易</button>
      	<button type="button" onclick="changeStatus('invalidate');">标记为失效</button>
      </c:if>
      <c:if test="${houseForm.houseStatus eq 'finished' || houseForm.houseStatus eq 'invalidate'}">
      	<button type="button" onclick="changeStatus('noneAudit');">撤销为未审核</button>
      </c:if>
      </td>
    </tr>
    </c:if>
    <tr bgcolor="f5f5f5"> 
      <td width="20%"><div align="right">房源标题：</div></td>
      <td width="80%" valign="middle"><html:text disabled="<%=isReadOnly%>" property="title" size="50"/>
        <html:errors property="title"/>
      </td>
    </tr>
    <c:if test="${houseForm.method eq 'edit'}">
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">房源状态：</div></td>
      <td>
      	<bean:message key="info.house.status.${houseForm.houseStatus}"/>
      	<c:if test="${houseForm.houseStatus eq 'audited'}">(<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${houseForm.auditTime}"/>)</c:if>
      	<c:if test="${houseForm.houseStatus eq 'published'}">(<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${houseForm.publishTime}"/>)</c:if>
      	<c:if test="${houseForm.houseStatus eq 'finished'}">(<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${houseForm.finishTime}"/>)</c:if>
      </td>
    </tr>
    </c:if>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">负责人：</div></td>
      <td>
      <table>
      	<tr>
      		<td><span style="vertical-align:middle;" id="employeeNameLabel">${houseForm.employeeName == null || houseForm.employeeName == '' ? '-' : houseForm.employeeName}</span></td>
      		<td>&nbsp;&nbsp;</td>
      		<c:if test="${houseForm.houseStatus eq 'noneAudit'}">
      		<td><img src="/images/delete2.gif" onclick="deleteEmployee();" style="cursor:hand;" title="删除内部用户"/></td>
      		<td><img src="/images/selectBuilding.png" onclick="openSelectEmployee();" style="cursor:hand;" title="选择内部用户"/></td>
      		<td>(留空则默认为当前用户)</td>
      		</c:if>
      	</tr>
      </table>
      <html:hidden property="employeeName" styleId="employeeName"/>
      </td>
    </tr>
    <!-- ################## 基本信息 ######################### -->
    <tr bgcolor="f5f5f5"> 
      <td><div align="right"><bean:message key="info.area.1"/>：</div></td>
      <td>
      	<html:select disabled="<%=isReadOnly%>" property="topAreaId" styleId="topAreaId" onchange="getAreas();">
      		<html:option value=""></html:option>
      		<html:options collection="tops" property="areaId" labelProperty="name"/>
      	</html:select>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right"><bean:message key="info.area.2"/>：</div></td>
      <td>
      	<html:select disabled="<%=isReadOnly%>" property="areaId" styleId="areaId">
      		<html:option value=""></html:option>
      		<html:options collection="lows" property="areaId" labelProperty="name"/>
      	</html:select>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">地址：</div></td>
      <td valign="middle"><html:text disabled="<%=isReadOnly%>" property="address" size="50"/>
      <html:errors property="address"/>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">面积：</div></td>
      <td valign="middle"><html:text disabled="<%=isReadOnly%>" property="space" size="50"/>
      <html:errors property="space"/>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">所属客户：</div></td>
      <td valign="middle">
      <table>
      	<tr>
      		<td><span style="vertical-align:middle;" id="userNameLabel">${houseForm.userName == null ? '-' : houseForm.userName}</span></td>
      		<td>&nbsp;&nbsp;</td>
      		<% if (isReadOnly) { %>
      		<td>&nbsp;&nbsp;</td>
      		<td>&nbsp;&nbsp;</td>
      		<% } else { %>
      		<td><img src="/images/delete2.gif" onclick="deleteUser();" style="cursor:hand;" title="删除客户"/></td>
      		<td><img src="/images/selectBuilding.png" onclick="openSelectUsers();" style="cursor:hand;" title="选择客户"/></td>
      		<% } %>
      		
      	</tr>
      </table>
      <html:hidden property="userId" styleId="userId"/>
      </td>
    </tr>
    <tr bgcolor="f5f5f5" valign="middle"> 
      <td><div align="right">所属楼盘：</div></td>
      <td valign="middle">
      <table>
      	<tr>
      		<td><span style="vertical-align:middle;" id="buildingNameLabel">${houseForm.buildingName == null ? '-' : houseForm.buildingName}</span></td>
      		<td>&nbsp;&nbsp;</td>
      		<% if (isReadOnly) { %>
      		<td>&nbsp;&nbsp;</td>
      		<td>&nbsp;&nbsp;</td>
      		<% } else { %>
      		<td><img src="/images/delete2.gif" onclick="deleteBuilding();" style="cursor:hand;" title="删除楼盘"/></td>
      		<td><img src="/images/selectBuilding.png" onclick="openSelectWindow();" style="cursor:hand;" title="选择楼盘"/></td>
      		<% } %>
      		
      	</tr>
      </table>
      <html:hidden property="buildingId" styleId="buildingId"/>
      </td>
    </tr>
    <%
    List<Config> cs = (List<Config>) request.getAttribute("cs");
    Set<Config> selectedConfigs = (Set<Config>) request.getAttribute("selectedConfigs");
	%>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">房屋配置：</div></td>
      <td valign="middle">
      <%
      for (int i = 0; i < cs.size(); i++) {
    	  Config c = cs.get(i);
    	  boolean checked = false;
    	  if (null != selectedConfigs) {
	    	  for (Config s: selectedConfigs) {
	           if (c.getConfigId() == s.getConfigId()) {
	              checked = true;
	              break;
	           }
	        }
    	  }
    	  %>
    	  <input name="configIds" <%=isReadOnly ? "disabled='disabled'" : ""%> type="checkbox"<%=checked?"checked=\"checked\"":""%> value="<%=c.getConfigId()%>"/><%=c.getName()%>&nbsp;&nbsp;
    	  <%
    	  if ((i+1) % 6 == 0) {
    		  out.print("<br/>");
    	  }
      }
      %>
      <input id="selectAllCheck" <%=isReadOnly ? "disabled='disabled'" : ""%> type="checkbox" <%=null != selectedConfigs && cs.size()==selectedConfigs.size()?"checked=\"checked\"":""%> onclick="selectAll('configIds', this);"/>全选
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">房源类型：</div></td>
      <td>
      	<html:select disabled="<%=isReadOnly%>" property="houseTypeId">
      		<html:option value=""></html:option>
      		<html:options collection="hts" property="houseTypeId" labelProperty="name"/>
      	</html:select>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">地铁线：</div></td>
      <td>
      	<html:select disabled="<%=isReadOnly%>" property="metroId" styleId="metroId" onchange="getStations();">
      		<html:option value=""></html:option>
      		<html:options collection="ms" property="metroId" labelProperty="name"/>
      	</html:select>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">地铁站：</div></td>
      <td>
      	<html:select disabled="<%=isReadOnly%>" property="metroStationId" styleId="metroStationId">
      		<html:option value=""></html:option>
      		<html:options collection="mss" property="stationId" labelProperty="name"/>
      	</html:select>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">物业类型：</div></td>
      <td>
      	<html:select disabled="<%=isReadOnly%>" property="propertyTypeId">
      		<html:option value=""></html:option>
      		<html:options collection="ppts" property="propertyTypeId" labelProperty="name"/>
      	</html:select>
      </td>
    </tr>
    <!--tr bgcolor="f5f5f5"> 
      <td><div align="right">是否作为热点推荐房源：</div></td>
      <td valign="middle">
      <ht ml:che ckbox disab led="" p roperty="isHot"/>
      <input type="hidden" name="isHot">
      </td>
    </tr-->
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">所属社区/街道办：</div></td>
      <td valign="middle"><html:text disabled="<%=isReadOnly%>" property="community" size="50"/>
        <html:errors property="community"/>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">管理费信息：</div></td>
      <td valign="middle"><html:text disabled="<%=isReadOnly%>" property="managePrice" size="50"/>
        <html:errors property="managePrice"/>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">总楼层：</div></td>
      <td valign="middle"><html:text disabled="<%=isReadOnly%>" property="floorAll" styleId="floorAll" size="50"/>
        <html:errors property="floorAll"/>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">所在楼层：</div></td>
      <td valign="middle"><html:text disabled="<%=isReadOnly%>" property="floorAt" styleId="floorAt" size="50"/>
        <html:errors property="floorAt"/>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">始建时间：</div></td>
      <td valign="middle">
        <input name="beginDate" id="beginDate" <%=isReadOnly ? "disabled='disabled'" : ""%>
              value="<fmt:formatDate value='${houseForm.beginDate}' pattern='yyyy-MM-dd' />" />
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">点击数：</div></td>
      <td>${houseForm.hits}</td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">房源介绍：</div></td>
      <td>
      <% if (!isReadOnly) { %>
      <html:textarea property="intro" styleId="intro" rows="25" cols="60"></html:textarea>
      <% } else { %>
      ${houseForm.intro}
      <% } %>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">地图信息：</div></td>
      <td>
      <% if (!isReadOnly) { %>
      <html:textarea property="mapInfo" styleId="mapInfo" rows="25" cols="60"></html:textarea>
      <% } else { %>
      ${houseForm.mapInfo}
      <% } %>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td><div align="right">备注：</div></td>
      <td>
      <% if (!isReadOnly) { %>
      <html:textarea property="remark" styleId="remark" rows="25" cols="60"></html:textarea>
      <% } else { %>
      ${houseForm.remark}
      <% } %>
      </td>
    </tr>
    <!-- ################## 基本信息 ######################### -->
    <tr bgcolor="f5f5f5"> 
      <td colspan="2"><div align="center"> 
          <button <%=isReadOnly ? "disabled='disabled'" : ""%> type="submit" class="frm_btn"><bean:message key="display.save"/></button>
      </div></td>
    </tr>
  </table>
</html:form>
<br>
</body>
</html>